#include <QApplication>
#include <QScreen>

#include "mainwindow.h"
#include <log_util.h>

void setWindowInCenter(MainWindow &w);

int main(int argc, char *argv[]) {
    LogUtil::init(spdlog::level::info,"../logs/app.log");
    std::shared_ptr<spdlog::logger> log = LogUtil::getLogger("app");
    
    QApplication a(argc, argv);
    MainWindow   w;
    setWindowInCenter(w);
    w.show();
    
    SPDLOG_LOGGER_INFO(log,fmt::format("hello qt"));
    
    return a.exec();
}

#define SHOW_WINDOW_IN_PRIMARY_SCREEN 1

void setWindowInCenter(MainWindow &w) {
#if SHOW_WINDOW_IN_PRIMARY_SCREEN
    // 获取主屏幕的指针
    QScreen *primaryScreen = QGuiApplication::primaryScreen();
    // 获取主屏幕的可用工作区几何信息
    QRect availableGeometry = primaryScreen->availableGeometry();
#else
    // 获取当前屏幕的可用工作区几何信息
    QScreen *currentScreen     = QGuiApplication::screenAt(w.pos());
    QRect    availableGeometry = currentScreen->availableGeometry();
#endif
    // 计算窗口居中显示的位置
    int x = availableGeometry.x() + (availableGeometry.width() - w.width()) / 2;
    int y = availableGeometry.y() + (availableGeometry.height() - w.height()) / 2;

    // 移动窗口到居中的位置
    w.move(x, y);
}
